package com.skivingcloud.report.service.impl;

import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.skivingcloud.admin.sys.entity.SysLog;
import com.skivingcloud.admin.sys.entity.SysUser;
import com.skivingcloud.report.entity.ReportScreenTpl;
import com.skivingcloud.report.entity.ReportType;
import com.skivingcloud.report.mapper.ReportScreenTplMapper;
import com.skivingcloud.report.service.ReportScreenTplService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.skivingcloud.common.utils.PageParameter;

/**
 * 大屏模板表 服务层实现。
 *
 * @author skivingcloud
 * @since 2024-11-07
 */
@Service
public class ReportScreenTplServiceImpl extends ServiceImpl<ReportScreenTplMapper, ReportScreenTpl> implements ReportScreenTplService {

    /**
     * 分页查询大屏模板表
     *
     * @param parameter 查询参数
     * @return 分页查询结果
     */
    @Override
    public Page<ReportScreenTpl> queryByPage(PageParameter<ReportScreenTpl> parameter){
        Page<ReportScreenTpl> page = new Page<>(parameter.getPage(), parameter.getPageSize());
        QueryWrapper queryWrapper = QueryWrapper.create().from(ReportScreenTpl.class).as("rc")
                .join(ReportType.class).as("rt").on(
                        wrapper -> wrapper.where(ReportScreenTpl::getReportType).eq(ReportType::getId)
                );
        if (parameter.getParam() != null) {
            //查询条件
            if (StringUtils.isNoneBlank(parameter.getParam().getId())) {
                queryWrapper.and(ReportScreenTpl::getId).like(parameter.getParam().getId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getTenantId())) {
                queryWrapper.and(ReportScreenTpl::getTenantId).like(parameter.getParam().getTenantId());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getTplCode())) {
                queryWrapper.and(ReportScreenTpl::getTplCode).like(parameter.getParam().getTplCode());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getTplName())) {
                queryWrapper.and(ReportScreenTpl::getTplName).like(parameter.getParam().getTplName());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getReportType())) {
                queryWrapper.and(ReportScreenTpl::getReportType).like(parameter.getParam().getReportType());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getImgUrl())) {
                queryWrapper.and(ReportScreenTpl::getImgUrl).like(parameter.getParam().getImgUrl());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getBackground())) {
                queryWrapper.and(ReportScreenTpl::getBackground).like(parameter.getParam().getBackground());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getCreator())) {
                queryWrapper.and(ReportScreenTpl::getCreator).like(parameter.getParam().getCreator());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getUpdater())) {
                queryWrapper.and(ReportScreenTpl::getUpdater).like(parameter.getParam().getUpdater());
            }
            if (StringUtils.isNoneBlank(parameter.getParam().getDelFlag())) {
                queryWrapper.and(ReportScreenTpl::getDelFlag).like(parameter.getParam().getDelFlag());
            }
        }
        return this.page(page, queryWrapper);
    }
}
